package com.etoak.rst.sys.employee.controller;

import com.etoak.rst.sys.employee.Dto.EmpDTO;
import com.etoak.rst.sys.employee.entity.Employee;
import com.etoak.rst.sys.employee.service.IEmployeeService;
import com.etoak.rst.sys.util.JsonResponse;
import com.etoak.rst.sys.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
public class EmController {

    @Autowired //先类型 再名 完成DI
    private IEmployeeService service;

    /*分页+模糊
    * */
    @GetMapping("/querySome")
    public JsonResponse querySome(EmpDTO dto){
        List<Employee> data = service.querySome(dto);
        PageInfo<Employee> info = new PageInfo<>(data);
        int a = 1/0;
        return data!=null&&data.size()>0? Result.success("200","success",info):
                    Result.failed("20001","failed","查询失败");
    }


    /*
    * 添加员工
    * */
    @PostMapping("/addEmp")
    public JsonResponse addEmp(@RequestBody Employee emp){
        boolean flag = service.addEmp(emp);
        return flag?Result.success("200","success","添加成功"):
                    Result.failed("20001","failed","添加失败");
    }

    /*删除员工
    * */
    @DeleteMapping("/{eid}")
    public JsonResponse delEmp(@PathVariable int eid){
        boolean flag = service.delEmp(eid);
        return flag?Result.success("200","success","删除成功"):
                Result.failed("20001","failed","删除失败");
    }

    /*修改员工
    * */
    @PutMapping("/upEmp")
    public JsonResponse upEmp(@RequestBody Employee emp){
        boolean flag = service.upEmp(emp);
        return flag?Result.success("200","success","修改成功"):
                Result.failed("20001","failed","修改失败");
    }














}
